﻿@*对客户的用量统计后台管理可能也用的着，所以本应该封装到Web.Core项目中，并且按小组件的方式开发
但现在敢进度，现在直接全部写在这个页面里吧*@
@page "/cust"
@inherits OwningComponentBase
@attribute [Authorize(PermissionNames.Customer)]
@inject NavigationManager Navigation
<MudStack>
    <MudStack Row  Justify="@Justify.Center" Spacing="7" >
        <MudChipSet @bind-SelectedChip="selected" Mandatory Filter SelectedChipsChanged="@Shuaxin">
            <MudChip Default="true" Text="dept" Variant="Variant.Outlined" SelectedColor="Color.Primary">按部门</MudChip>
            <MudChip Text="dev" Variant="Variant.Outlined" SelectedColor="Color.Primary">按设备</MudChip>
        </MudChipSet>
        <MudChipSet @bind-SelectedChip="yf" Mandatory Filter SelectedChipsChanged="@Shuaxin">
            <MudChip Default="true" Text="本月" Variant="Variant.Outlined" SelectedColor="Color.Primary">本月</MudChip>
            <MudChip Text="上月" Variant="Variant.Outlined" SelectedColor="Color.Primary">上月</MudChip>
        </MudChipSet>
    </MudStack>
    <MudGrid>
        @if (bumenTonji)
        {
            <MudItem xs="12" md="9">
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">部门印量排行</MudText>
                        </CardHeaderContent>
                    </MudCardHeader>
                    <MudCardContent>
                        <BXJGBlazorECharts @ref="bumenTubiao" style="height:360px;" />
                    </MudCardContent>
                </MudCard>
            </MudItem>
            <MudItem xs="12" md="3">
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">部门印量占比</MudText>
                        </CardHeaderContent>
                    </MudCardHeader>
                    <MudCardContent>
                        <BXJGBlazorECharts @ref="bumenTubiaoBing" style="height:360px;" />
                    </MudCardContent>
                </MudCard>
            </MudItem>

            <MudItem xs="12">
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">数据</MudText>
                        </CardHeaderContent>
                        <CardHeaderActions>
                            <MudButton OnClick="daochuExcel" StartIcon="@Icons.Custom.FileFormats.FileExcel" Variant="Variant.Outlined" Color="Color.Primary">导出excel</MudButton>
                        </CardHeaderActions>
                    </MudCardHeader>
                    <MudCardContent>
                    </MudCardContent>
                </MudCard>
            </MudItem>
        }
        else
        {
            <MudItem xs="12" sm="9">
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">设备印量排行</MudText>
                        </CardHeaderContent>
                    </MudCardHeader>
                    <MudCardContent>
                        <BXJGBlazorECharts @ref="shebeiTubiao" style="height:360px;" />
                    </MudCardContent>
                </MudCard>
            </MudItem>
            <MudItem xs="12" sm="3">
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">设备印量占比</MudText>
                        </CardHeaderContent>
                    </MudCardHeader>
                    <MudCardContent>
                        <BXJGBlazorECharts @ref="shebeiTubiaoBing" style="height:360px;" />
                    </MudCardContent>
                </MudCard>
            </MudItem>
            <MudItem xs="12">
                <MudCard>
                    <MudCardHeader>
                        <CardHeaderContent>
                            <MudText Typo="Typo.h6">数据</MudText>
                        </CardHeaderContent>
                        <CardHeaderActions>
                            <MudButton OnClick="daochuExcel" StartIcon="@Icons.Custom.FileFormats.FileExcel" Variant="Variant.Outlined" Color="Color.Primary">导出excel</MudButton>
                        </CardHeaderActions>
                    </MudCardHeader>
                    <MudCardContent>
                       
                    </MudCardContent>
                </MudCard>
            </MudItem>
        }


    </MudGrid>
</MudStack>
@code {
    MudChip selected;//选择部门或设备统计
    MudChip yf;//统计月份
    BXJGBlazorECharts bumenTubiao;
    BXJGBlazorECharts bumenTubiaoBing;
    BXJGBlazorECharts shebeiTubiao;
    BXJGBlazorECharts shebeiTubiaoBing;
    ////统计数据的原始数据
    //PaperStatisticsOuDto bumenTonjiXuanxiang;
    //PaperStatisticsEquipmentDto shebeiTongjiXuangxiang;
    /// <summary>
    /// true部门统计 false设备统计
    /// </summary>
    private bool bumenTonji => selected == default || selected.Text == "dept";

    //protected override async Task OnAfterRenderAsync(bool firstRender)
    //{
    //    //await base.OnAfterRenderAsync(firstRender);
    //    if (!firstRender)
    //        return;
    //    //图表生命周期可能有点问题，刷新前前端可能还没初始化好，所以这里加个语句；SetOption内部没用，必须在这里
    //    await Task.Yield();
    //    //统计图表的echart选项对象
    //    dynamic bumenTonjiShuju = new
    //    {
    //        tooltip = new
    //        {
    //            trigger = "axis",
    //            axisPointer = new
    //            {
    //                axisPointer = "shadow"
    //            }
    //        },
    //        legend = new object(),
    //        xAxis = new
    //        {
    //            type = "category",
    //            data = new List<string> { "xxx", "yyy" }
    //        },
    //        yAxis = new
    //        {
    //            type = "value"
    //        },
    //    };
    //    dynamic bing = new
    //    {
    //        tooltip = new { trigger = "item" },
    //        legend = new object(),
    //        series = new[]
    //        {
    //            new
    //            {
    //                name="部门印量占比",
    //                type="pie",
    //                radius=new[]{"40%","70%"},
    //                avoidLabelOverlap=false,
    //                itemStyle = new
    //                {
    //                    borderRadius=10,
    //                    borderColor="#fff",
    //                    borderWidth=2
    //                },
    //                label = new
    //                {
    //                    show=false,
    //                    position="center",
    //                },
    //                emphasis = new
    //                {
    //                    label = new
    //                    {
    //                        show=true,
    //                        fontSize=20,
    //                        fontWeight="bold"
    //                    }
    //                },
    //                labelLine = new
    //                {
    //                    show=false
    //                },
    //                data = new[]
    //                {
    //                    new
    //                    {
    //                        value=1038,
    //                        name="aaaa"
    //                    },
    //                    new
    //                    {
    //                        value=134,
    //                        name="bbb"
    //                    },
    //                    new
    //                    {
    //                        value=434,
    //                        name="ccc"
    //                    }
    //                }
    //            }
    //}
    //    };
    //    Task t1, t2;
    //    if (bumenTonji)
    //    {
    //        t1 = bumenTubiao.SetOption(bumenTonjiShuju);
    //        t2 = bumenTubiaoBing.SetOption(bing);
    //    }
    //    else
    //    {
    //        t1 = shebeiTubiao.SetOption(bumenTonjiShuju);
    //        t2 = shebeiTubiaoBing.SetOption(bing);
    //    }
    //    await Task.WhenAll(t1, t2);
    //}

    //protected override async Task OnInitializedAsync()
    //{
    //    await Task.Delay(3000);
    //    bumenTonjiXuanxiang = await appService.GetOu(new QueryInput { TimeRange = yf?.Text == "上月" ? TimeRange.LastMonth : TimeRange.ThisMonth });
    //        await bumenTubiao.SetOption(new
    //        {
    //            xAxis = new
    //            {
    //                //type = "category",
    //                data = bumenTonjiXuanxiang.Items.Select(d => d.OuName)
    //            },
    //            series = new[]
    //            {
    //                new
    //                {
    //                    name = "A3黑白",
    //                    type = "bar",
    //                    stack = "total",
    //                    barWidth=40,
    //                    label = new
    //                    {
    //                        show = true
    //                    },
    //                    emphasis = new
    //                    {
    //                        focus = "series",
    //                    },
    //                    data = bumenTonjiXuanxiang.Items.Select(c=>c.A3BlackAndWhite)
    //                },
    //                new
    //                {
    //                    name = "A3彩色",
    //                    type = "bar",
    //                    stack = "total",
    //                    barWidth=40,
    //                    label = new
    //                    {
    //                        show = true
    //                    },
    //                    emphasis = new
    //                    {
    //                        focus = "series",
    //                    },
    //                    data = bumenTonjiXuanxiang.Items.Select(c=>c.A3TrueColor)
    //                },
    //                new
    //                {
    //                    name = "A4黑白",
    //                    type = "bar",
    //                    stack = "total",
    //                    barWidth=40,
    //                    label = new
    //                    {
    //                        show = true
    //                    },
    //                    emphasis = new
    //                    {
    //                        focus = "series",
    //                    },
    //                    data = bumenTonjiXuanxiang.Items.Select(c=>c.A4BlackAndWhite)
    //                },
    //                new
    //                {
    //                    name = "A4彩色",
    //                    type = "bar",
    //                    stack = "total",
    //                    barWidth=40,
    //                    label = new
    //                    {
    //                        show = true
    //                    },
    //                    emphasis = new
    //                    {
    //                        focus = "series",
    //                    },
    //                    data = bumenTonjiXuanxiang.Items.Select(c=>c.A4TrueColor)
    //                }
    //}
    //        });
    //}

    //这方法刷新太快，图表可能还没准备好
    async Task Shuaxin(MudChip[] chips)
    {
      
    }

    void daochuExcel()
    {
        //TimeRange tr = yf?.Text == "上月" ? TimeRange.LastMonth : TimeRange.ThisMonth;
        //if (bumenTonji)
        //    Navigation.NavigateTo($"/api/services/{CustConsts.Cust}/PaperStatistics/ExportOU?TimeRange={(int)tr}", true);
        //else
        //    Navigation.NavigateTo($"/api/services/{CustConsts.Cust}/PaperStatistics/ExportEQ?TimeRange={(int)tr}", true);
    }
}